import { h } from 'preact'
import Router from 'preact-router'
import AsyncRoute from 'preact-async-route';
import linkState from 'linkstate';
// import Home from '../pages/Home'
// import About from '../pages/About'
// import Test from '../pages/Test'

const getLoading = (route) => {
    // if (this.state.ssrShown) {
    return <div>loading...</div>;
    // } else {
    // return <div dangerouslySetInnerHTML={{ __html: this.state.ssrText }} />;
    // }
}

const getTest = (url, cb, props) => {
    const test = 'Test'
    const componentOrPromise = import('../pages/' + test);
    if (componentOrPromise.then) {
        return componentOrPromise.then(module => module.default);
    }
    else if (componentOrPromise.default) {
        cb({ component: componentOrPromise.default });
    }
}
const getHome = (url, cb, props) => {
    const componentOrPromise = import('../pages/Home');

    if (componentOrPromise.then) {
        console.info('----------------------then')
        return componentOrPromise.then(module => module.default);
    }
    else if (componentOrPromise.default) {
        console.info('----------------------default')
        cb({ component: componentOrPromise.default });
    }
}
const getAbout = (url, cb, props) => {
    const componentOrPromise = import('../pages/About');
    if (componentOrPromise.then) {
        return componentOrPromise.then(module => module.default);
    }
    else if (componentOrPromise.default) {
        cb({ component: componentOrPromise.default });
    }
}
export default ({ url }) => (
    <Router url={url}>
        {/* <Home path="/"></Home> */}
        {/* <About path="/about"></About> */}
        <AsyncRoute path='/' getComponent={getHome}></AsyncRoute>
        <AsyncRoute path='/about' getComponent={getAbout}></AsyncRoute>
        <AsyncRoute path='/test' getComponent={getTest}></AsyncRoute>
        {/* <Test path="/test"></Test> */}
    </Router>
)
